package javbot.gui;

import java.io.FileNotFoundException;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import javbot.GlobalClass;

public class MailSendPanel extends JPanel {

	private static final long serialVersionUID = 2186857722722149805L;
	private JLabel jLabel = null;
	private JTextField serverTextField = null;
	private JButton saveButton = null;

	/**
	 * This method initializes serverTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getServerTextField() {
		if (serverTextField == null) {
			serverTextField = new JTextField();
			serverTextField.setBounds(new java.awt.Rectangle(128,9,213,20));
		}
		return serverTextField;
	}

	/**
	 * This method initializes saveButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getSaveButton() {
		if (saveButton == null) {
			saveButton = new JButton();
			saveButton.setBounds(new java.awt.Rectangle(256,42,82,23));
			saveButton.setText("Save");

			saveButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					try {						
						GlobalClass.mailProps.setMailServerOut(serverTextField.getText());
						GlobalClass.mailProps.saveMailProps();						
					} catch (FileNotFoundException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					close();
				}
			});			
		}
		return saveButton;
	}

	/**
	 * This is the default constructor
	 */
	public MailSendPanel() {
		super();
		initialize();
		serverTextField.setText(GlobalClass.mailProps.getMailServerOut());
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		jLabel = new JLabel();
		jLabel.setText("Outgoing Mail Server:");
		jLabel.setBounds(new java.awt.Rectangle(4,9,121,16));
		this.setLayout(null);
		this.setSize(351, 77);
		this.add(jLabel, null);
		this.add(getServerTextField(), null);
		this.add(getSaveButton(), null);
	}

	public void close() {
		((JDialog) getParent().getParent().getParent()).dispose();
	}	
	
}  //  @jve:decl-index=0:visual-constraint="10,9"
